//
//  HACRectRenderer.m
//  Pods
//
//  Created by Hotacool on 2017/8/31.
//
//

#import "HACRectRenderer.h"
#import "HACBasicComponents.h"
#import "HACRectProvider.h"
#import "HACChartUtils.h"

@implementation HACRectRenderer
- (void)drawInRect:(CGRect)rect context:(CGContextRef)context {
    [super drawInRect:rect context:context];
    
    NSArray *datas;
    if ([self.provider conformsToProtocol:@protocol(HACRectProvider)]) {
        id<HACRectProvider> provider = self.provider;
        datas = [provider rectDatasInRect:rect];
    }
    for (HACRectComponents *rectItem in datas) {
        UIColor *color = rectItem.lineColor;
        
        if (rectItem.isSoildFill) {
            CGContextSetFillColorWithColor(context, color.CGColor);
            CGContextFillRect(context, rectItem.pillarRect);
        } else {
            CGContextSetStrokeColorWithColor(context, color.CGColor);
            CGContextStrokeRect(context, rectItem.pillarRect);
        }
        
        [HACChartUtils drawLine:context pt1:rectItem.line1.start pt2:rectItem.line1.end clr:color width:rectItem.lineBolder];
        [HACChartUtils drawLine:context pt1:rectItem.line2.start pt2:rectItem.line2.end clr:color width:rectItem.lineBolder];
    }
}
@end
